package com.muyu.danmo.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.danmo.domain.DanmoAncientDynasties;
import com.muyu.danmo.service.IDanmoAncientDynastiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 古代朝代Controller
 *
 * @author yangle
 * @date 2024-09-21
 */
@RestController
@RequestMapping("/dynasties")
public class DanmoAncientDynastiesController extends BaseController
{
    @Autowired
    private IDanmoAncientDynastiesService danmoAncientDynastiesService;

    /**
     * 查询古代朝代列表
     */
//    @RequiresPermissions("system:dynasties:list")
    @PostMapping("/list")
    public Result list(@RequestBody DanmoAncientDynasties danmoAncientDynasties)
    {
//        startPage();
        List<DanmoAncientDynasties> list = danmoAncientDynastiesService.selectDanmoAncientDynastiesList(danmoAncientDynasties);
        return  Result.success(list);
    }

    /**
     * 导出古代朝代列表
     */
//    @RequiresPermissions("system:dynasties:export")
    @Log(title = "古代朝代", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoAncientDynasties danmoAncientDynasties)
    {
        List<DanmoAncientDynasties> list = danmoAncientDynastiesService.selectDanmoAncientDynastiesList(danmoAncientDynasties);
        ExcelUtil<DanmoAncientDynasties> util = new ExcelUtil<DanmoAncientDynasties>(DanmoAncientDynasties.class);
        util.exportExcel(response, list, "古代朝代数据");
    }

    /**
     * 获取古代朝代详细信息
     */
//    @RequiresPermissions("system:dynasties:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoAncientDynastiesService.selectDanmoAncientDynastiesById(id));
    }

    /**
     * 新增古代朝代
     */
//    @RequiresPermissions("system:dynasties:add")
    @Log(title = "古代朝代", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoAncientDynasties danmoAncientDynasties)
    {
        return toAjax(danmoAncientDynastiesService.insertDanmoAncientDynasties(danmoAncientDynasties));
    }

    /**
     * 修改古代朝代
     */
//    @RequiresPermissions("system:dynasties:edit")
    @Log(title = "古代朝代", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoAncientDynasties danmoAncientDynasties)
    {
        return toAjax(danmoAncientDynastiesService.updateDanmoAncientDynasties(danmoAncientDynasties));
    }

    /**
     * 删除古代朝代
     */
//    @RequiresPermissions("system:dynasties:remove")
    @Log(title = "古代朝代", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoAncientDynastiesService.deleteDanmoAncientDynastiesByIds(ids));
    }
}
